<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./css/bootstrap.css">
    <style>
        .container {
            width: 400px;
            height: 600px;
        }
    </style>
</head>

<body>
    <div class="container">
        <h2>编辑信息</h2>
        <div class="form-group">
            <label>username</label>
            <input type="text" class="form-control" name="username">
        </div>
        <div class="form-group">
            <label>age</label>
            <input type="text" class="form-control" name="age">
        </div>
        <input onclick="save()" class="btn btn-success" type="submit" value="确认">

        <button class="btn btn-info">
            <a href="./index.html">返回</a>
        </button>
    </div>
</body>
<script src="./js/jquery.min.js"></script>
<script>
    var id = location.hash.replace('#', '')
    console.log(id);
    $.get('/find', { id: id }).done(function (result) {
        $('[name=username]').val(result.username);
        $('[name=age]').val(result.age)
    })
    function save() {
        var username = $('[name=username]').val();
        var age = $('[name=age]').val();
        $.post('/edit', {
            username: username,
            age: age,
            id: id
        }).then(function () {
            location.href = "./index.html"
        })
    }
</script>

</html>